package jsyf.oa.web.report;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.WechatShareFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by WHH-PC on 2018/2/24.
 */
@Api(value = "微信分享报表接口", description = "微信分享报表接口")
@Controller
@RequestMapping("/reportWechatShare")
public class WechatShareReportController {
    @Resource
    private WechatShareFacade wechatShareFacade;


    @RequestMapping(value = "/getWechatShareTotal.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "微信转发汇总数",
            notes = "微信转发汇总数",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getWechatShareTotal(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = JSON.parseObject(jsonData);
        JSONObject result = this.wechatShareFacade.getWechatShareTotal(obj);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }

    @RequestMapping(value = "/getMonthShareList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取某个月的分享链接",
            notes = "获取某个月的分享链接",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getMonthShareList(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = JSON.parseObject(jsonData);
        List<JSONObject> records = this.wechatShareFacade.getMonthShareList(obj);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }

    @RequestMapping(value = "/getShareRegionList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取大区经理微信转发列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getShareRegionList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = wechatShareFacade.getShareRegionList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getShareSupportRegionList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取区域支持微信转发列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getShareSupportRegionList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = wechatShareFacade.getShareSupportRegionList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getShareSalerManagerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取销售管理经理微信转发列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getShareManagerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = wechatShareFacade.getShareSalerManagerList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getShareCompanyList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取集团管理层微信转发列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getShareCompanyList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        List<JSONObject> list = wechatShareFacade.getShareCompanyList(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }
    @RequestMapping(value = "/getShareByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "某个公司微信转发汇总",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getShareByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        JSONObject result = wechatShareFacade.getShareByCompanyId(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }

}
